<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // var a = [39, 6, 1, 8, 20, 40, 4, 4, 42, 18, 50];
        // var index = 0;//接收未确定元素最小值的索引
        // for (i = 0; i < a.length; i++) {  
        //     index = i; //假定a[i]为最小值,让index记录这个最小值的下标(索引).
        //     for (j = i + 1; j < a.length; j++) {
        //         if (a[index]>a[j]) {//比数值
        //             index = j;//赋值索引   ,使index指向最小的那个数
        //         }
        //     }
        //     if (index !== i) {
        //         var temp = a[i];
        //         a[i] = a[index];
        //         a[index] = temp;
        //     }
        // }
        // console.log(a);//[1, 4, 4, 6, 8, 18, 20, 39, 40, 42, 50]



       
    </script>
</body>

</html>